package com.easyschool.model.school;

import java.sql.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import com.easyschool.webservices.adapter.WSDateAdapter;

@XmlRootElement
@Entity
@Table(name="class")
public class Class {
	@Id
	@GeneratedValue
	@Column(name = "IDCLASS")
	private Integer idClass;
	
	@Column(name = "LIBELLE")
	private String libelle;
	
	@Column(name = "CREATE_DATE")
	private Date createDate;
	
	@Column(name= "schoolId")
	private Integer schoolId;
	
	@ManyToOne(fetch=FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name="schoolId", insertable=false, nullable=false, updatable=false)
	private School school;
	
//	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
//	@JoinTable(name = "user_class", 
//			inverseJoinColumns = {@JoinColumn(name="IDUSER", nullable=false)}, 
//			joinColumns={@JoinColumn(name="IDCLASS", nullable=false)})
//	private Set<User> professors = new HashSet<User>(0);
	

	public String getLibelle() {
		return libelle;
	}
	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}
	@XmlJavaTypeAdapter(WSDateAdapter.class)
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	
	
	public Integer getIdClass() {
		return idClass;
	}
	public Integer getSchoolId() {
		return schoolId;
	}
	public void setSchoolId(Integer schoolId) {
		this.schoolId = schoolId;
	}
	public void setIdClass(Integer idClass) {
		this.idClass = idClass;
	}
	public Class(){}
	
	public Class(Integer idClass){
		this.idClass = idClass;
	}


	
	public School getSchool() {
		return school;
	}
	public void setSchool(School school) {
		this.school = school;
	}
//	public Set<User> getProfessors() {
//		return professors;
//	}
//	public void setProfessors(Set<User> professors) {
//		this.professors = professors;
//	}
	public Class(Integer idClass, String libelle, Date createDate, Integer schoolId){
		this.createDate = createDate;
		this.idClass = idClass;
		this.libelle = libelle;
		this.schoolId = schoolId;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj != null && obj instanceof Class){
			return this.idClass.equals(((Class)obj).getIdClass());
		} else {
			return false;
		}
	}
	@Override
	public int hashCode() {
		return this.idClass.hashCode();
	}
	
	
	
}
